package string;

public class ReversePrefixOfWord2000 {
    public String reversePrefix(String word, char ch) {
        char[] chars = word.toCharArray();
        int index = -1;
        for (int i = 0; i < chars.length; i++) {
            if(chars[i]==ch){
                index=i;
                break;
            }
        }
        if(index==-1){
            return word;
        }
        int begin = 0;
        while (begin<index){
            char tmp = chars[begin];
            chars[begin] = chars[index];
            chars[index] = tmp;
            begin++;
            index--;
        }
        return String.valueOf(chars);
    }
}
